#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
--------------------------------------
    Author:     JiChao_Song
    Data  :     2020/5/8 下午1:40
--------------------------------------
"""
import unittest
from utils.requestsmain import Requests
from config import setting


class Login(unittest.TestCase):
    """
    登录接口
    """

    def setUp(self) -> None:
        """
        获取accesstoken
        :return:
        """
        self.url = '/organize/person/login'
        self.req = Requests(self.url)

    def tearDown(self) -> None:
        pass

    def test_login_01(self):
        """
        用户名和密码都正确
        :return: 登录成功
        """

        data = {
            'username': 'sjch123456',
            'password': '123456'
        }

        response = self.req.Post(data=data)

        code = response.json()['code']

        setting.ACCESS_TOKEN = response.json()['data']['accesstoken']

        self.assertEqual(code, 20000, msg=response.json())

    def test_login_02(self):
        """
        用户名正确, 密码错误
        :return: 密码错误
        """
        data = {
            'username': 'sjch123456',
            'password': '1234561'
        }

        response = self.req.Post(data=data)

        code = response.json()['code']

        self.assertEqual(code, 40108, msg=response.json())

    def test_login_03(self):
        """
        用户名正确, 密码错误
        :return: 用户名不存在
        """
        data = {
            'username': 'sjch1234',
            'password': '123456'
        }

        response = self.req.Post(data=data)

        code = response.json()['code']

        self.assertEqual(code, 40110, msg=response.json())


if __name__ == '__main__':
    unittest.main()
